package com.xbongbong.saas.enums.dictionary;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.saas.enums.OperateTypeEnum;
import lombok.Getter;

import java.util.Objects;

/**
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/6/28 19:46
 * @since v1.0
 */
@Getter
public enum IsCancelEnum {
    NOT_CANCEL(0, "enum.isCancel.name.not_cancel", "nonRed"),


    IS_CANCEL(1, "enum.isCancel.name.is_cancel", "hasRed"),
    ;

    IsCancelEnum(Integer code, String name, String attr) {
        this.code = code;
        this.name = name;
        this.attr = attr;
    }

    private Integer code;
    private String name;
    private String attr;

    /**
     * 通过code获取操作类型（发票作废 or 还原）
     * @param code
     * @return com.xbongbong.saas.enums.OperateTypeEnum
     * @author zcp
     * @date 2019/7/6 16:24
     * @since v1.0
     * @version v1.0
     */
    public static OperateTypeEnum getIsCancelByCode(Integer code){
        if (Objects.equals(code, NOT_CANCEL.code)) {
            return OperateTypeEnum.REVERT_CANCEL;
        } else if (Objects.equals(code, IS_CANCEL.code)) {
            return OperateTypeEnum.CANCEL;
        }
        return OperateTypeEnum.EDIT;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
